
import {_decorator,
    Component, EventKeyboard, log, macro, Node, systemEvent,
    game,
    SystemEventType,v2,Vec2} from 'cc';
import {Daidai} from "./Daidai";
const { ccclass, property } = _decorator;

@ccclass('InputCtrl')
export class InputCtrl extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    @property({type:Daidai})
    daidai:Daidai = null!;

    // private
    // moveDir = v2(0,0);

    onLoad(): void {
        // systemEvent.on(SystemEventType.KEY_DOWN, this.onKeyDown, this);
        // systemEvent.on(SystemEventType.KEY_UP, this.onKeyUp, this);
    }

    onDestroy(): void {
        // systemEvent.off(SystemEventType.KEY_DOWN, this.onKeyDown, this);
        // systemEvent.off(SystemEventType.KEY_UP, this.onKeyUp, this);
    }
    // onKeyDown(event: EventKeyboard){
    //     switch (event.keyCode) {
    //         case macro.KEY.w || macro.KEY.up:
    //             log("=== keydown called!");
    //             this.moveDir.y = -1;
    //             break;
    //         case macro.KEY.a || macro.KEY.left:
    //             this.moveDir.x = -1;
    //             break;
    //         case macro.KEY.s || macro.KEY.right:
    //             this.moveDir.y = 1;
    //             break;
    //         case macro.KEY.d || macro.KEY.right:
    //             this.moveDir.x = 1;
    //             break;
    //     }
    // }
    // onKeyUp(event: EventKeyboard){
    //     switch (event.keyCode) {
    //         case macro.KEY.w || macro.KEY.up:
    //             this.moveDir.y = 0;
    //             break;
    //         case macro.KEY.a || macro.KEY.left:
    //             this.moveDir.x = 0;
    //             break;
    //         case macro.KEY.s || macro.KEY.right:
    //             this.moveDir.y = 0;
    //             break;
    //         case macro.KEY.d || macro.KEY.right:
    //             this.moveDir.x = 0;
    //             break;
    //     }
    // }
    //
    // start () {
    //     // [3]
    // }
    //
    // update (deltaTime: number) {
    //     // [4]
    //     if (this.moveDir.x != 0 || this.moveDir.y != 0){
    //         this.daidai.onMove(this.moveDir);
    //     }
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.0/manual/en/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.0/manual/en/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.0/manual/en/scripting/life-cycle-callbacks.html
 */
